{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\t124\t132\t134\t142\t143\t\n",
      "213\t214\t231\t234\t241\t243\t\n",
      "312\t314\t321\t324\t341\t342\t\n",
      "412\t413\t421\t423\t431\t432\t\n",
      "有24个数。\n"
     ]
    }
   ],
   "source": [
    "# 题目：有四个数字：1、2、3、4，能组成多少个互不相同且无重复数字的三位数？各是多少？\n",
    "HOW_MANY = 0\n",
    "for item1 in range(1, 4 + 1):\n",
    "    for item2 in range(1, 4 + 1):\n",
    "        for item3 in range(1, 4 + 1):\n",
    "            if item1 != item2 and item2 != item3 and item3 != item1:\n",
    "                print(item1, item2, item3, sep = '', end = '\\t')\n",
    "                HOW_MANY += 1\n",
    "    print('')\n",
    "print('有', HOW_MANY, '个数。', sep = '')\n",
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您的奖金是：4.95万元。\n"
     ]
    }
   ],
   "source": [
    "# 题目：企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；\n",
    "# 利润高于10万元，低于20万元时，低于10万元的部分按10%提成，高于10万元的部分，可提成7.5%；\n",
    "# 20万到40万之间时，高于20万元的部分，可提成5%；\n",
    "# 40万到60万之间时高于40万元的部分，可提成3%；\n",
    "# 60万到100万之间时，高于60万元的部分，可提成1.5%，\n",
    "# 高于100万元时，超过100万元的部分按1%提成，\n",
    "# 从键盘输入当月利润I，求应发放奖金总数？\n",
    "ly = [1000000, 600000, 400000, 200000, 100000, 0]\n",
    "bl = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]\n",
    "tc = [39500, 33500, 27500, 17500, 10000, 0]\n",
    "d = {100: [0.01, 3.95], 60: [0.015, 3.35], 40: [0.03, 2.75], 20: [0.05, 1.75], 10: [0.075, 1], 0: [0.1, 0]}\n",
    "x = int(input('请输入您的利润：'))\n",
    "j = 0\n",
    "for it in d:\n",
    "    if x > it:\n",
    "        j = (x - it)*d[it][0] + d[it][1]\n",
    "        break\n",
    "print('您的奖金是：', j, '万元。', sep = '')\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{-99, 21, 261, 1581}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 题目：一个整数，它加上100后是一个完全平方数，再加上168又是一个完全平方数，请问该数是多少？\n",
    "# x + 100 = a * a\n",
    "# x + 100 + 168 = b * b\n",
    "# 令 b = a + k\n",
    "# (a + k) * (a + k) - a * a = 168\n",
    "# 2 * a * k + k * k = 168\n",
    "# k必须为偶数, 令k = 2t\n",
    "# a = 42/t - t\n",
    "# t是整数，要使a是整数，42/t必须是整数\n",
    "# t的取值只能是1,2,3,6,7,14,21,42\n",
    "# 所以a的值是41,19,11,1,-1,-11,-19,-41\n",
    "# 从a * a来看，正负不影响结果\n",
    "# a的取值[1,2,3,6]\n",
    "s = set()\n",
    "\n",
    "for a in [41, 19, 11, 1]:\n",
    "    s.add(a * a - 100)\n",
    "s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "158\n"
     ]
    }
   ],
   "source": [
    "# 题目：输入某年某月某日，判断这一天是这一年的第几天？\n",
    "x = input('请输入年月日（用空格隔开，如2021 12 18）：')\n",
    "l = x.split()\n",
    "l[0] = int(l[0])\n",
    "l[1] = int(l[1])\n",
    "l[2] = int(l[2])\n",
    "md = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334)\n",
    "if l[1] > 2 and ((l[0] % 400 == 0) or (l[0] % 4 == 0 and l[0] % 100 != 0)):\n",
    "    print (md[l[1] - 1] + l[2] + 1)\n",
    "else:\n",
    "    print(md[l[1] - 1] + l[2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 8]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 题目：输入三个整数x,y,z，请把这三个数由小到大输出。\n",
    "x = input('三个数字（用空格隔开，如2021 12 18）：')\n",
    "l = x.split()\n",
    "l[0] = int(l[0])\n",
    "l[1] = int(l[1])\n",
    "l[2] = int(l[2])\n",
    "a = l[:]\n",
    "length = len(a)\n",
    "for i in range(length):\n",
    "    for j in range(i + 1, length):\n",
    "        if a[i] > a[j]:\n",
    "            a[j] = a[i] + a[j]\n",
    "            a[i] = a[j] - a[i]\n",
    "            a[j] = a[j] - a[i]\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对给定的数列排序\n",
    "import random\n",
    "nums = list()\n",
    "for i in range(100):\n",
    "    nums.append(random.randint(0, 1000))\n",
    "nums\n",
    "\n",
    "def sort_by_key(nums:list[int]):\n",
    "    nums_l = list()\n",
    "    nums_r = list()\n",
    "    length = len(nums)\n",
    "    for it in nums[1:]:\n",
    "        if nums[0] > it:\n",
    "            nums_l.append(it)\n",
    "        else:\n",
    "            nums_r.append(it)\n",
    "    if len(nums_l) < 2:\n",
    "        pass\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "import PySimpleGUI as sg\n",
    "sg.change_look_and_feel('DarkAmber')\n",
    "layout = [[sg.T('这是一个非常基础的 PySimpleGUI layout', key='-output-')],\n",
    "          [sg.In(key='-in-')],\n",
    "          [sg.B('提交'), sg.B('退出')]]\n",
    "\n",
    "window = sg.Window('我的第一个Window', layout, grab_anywhere=True)\n",
    "\n",
    "while True:\n",
    "    event, values = window.read()\n",
    "    #print(event, values)\n",
    "    if event in (None, '退出'):\n",
    "        break\n",
    "    elif event == '提交':\n",
    "        window['-output-'].update(values['-in-'])\n",
    "window.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "b0d345c735fc2eae186f050c068afba514e752cd33cb3f00d8bf2e742802e055"
  },
  "kernelspec": {
   "display_name": "Python 3.10.0 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
